package com.etc.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.etc.entity.MedicalHistory;
import com.etc.entity.Prescription;
import com.etc.service.MedicalHistoryService;
import com.etc.service.MedicineService;
import com.etc.service.PrescriptionService;

/**
*@Author 陈伟杰
*@Date 2018年11月19日
*@Description 
*/
@Controller
public class PrescriptionController {
	@Autowired
	private MedicineService medicineService;
	@Autowired
	private PrescriptionService prescriptionService;
	@Autowired
	private MedicalHistoryService medicalHistoryService;
	
	/**
	 * 添加处方
	 * @return
	 */
	@RequestMapping(value="addPre",method=RequestMethod.POST)
	@ResponseBody
	public int insertPre(@RequestBody Prescription prescription){
		int medicineId = medicineService.selMedicineIdByName(prescription.getMedicineName());
		Prescription record = new Prescription();
		record.setMedicalOrders(prescription.getMedicalOrders());
		record.setTcid(prescription.getTcid());
		record.setTmedicinaid(medicineId);
		record.setTmedicinenum(prescription.getTmedicinenum());
		int i = prescriptionService.insert(record);
		return i;
		
	};
	
	/**
	 * 添加病史
	 * @param medicalHistory
	 * @return
	 */
	@RequestMapping(value="addMH",method=RequestMethod.POST)
	@ResponseBody
	public int insertMH(@RequestBody MedicalHistory medicalHistory){
		return medicalHistoryService.inserMedicalHistory(medicalHistory);
		
	}
}
